<template>
  <div>
    <!-- 产品导航栏部分 -->
    <div class="brief">
      <!-- 确定版心 -->
      <div class="w">
        <!-- 产品导航栏左侧 -->
        <div class="brief_le">
          <h3>{{ categoryView.category1Name }}</h3>
          <span style="margin: 0 10px">|</span>
          <a href="">{{ categoryView.category2Name }}</a>
        </div>
        <!-- 产品导航栏右侧 -->
        <div class="brief_ri">
          <a href="">概述页</a>
          <span>|</span>
          <a href="">参数页</a>
          <span>|</span>
          <a href="">F码通道</a>
          <span>|</span>
          <a href="">咨询客服</a>
          <span>|</span>
          <a href="">用户评价</a>
        </div>
      </div>
    </div>
    <!-- 产品介绍部分 -->
    <div class="detail w">
      <!-- 产品介绍左侧图片部分 -->
      <div class="detail_le">
        <div class="small">
          <div class="block">
            <el-carousel
              trigger="click"
              indicator-position="outside"
              height="560px"
              arrow="always"
            >
              <el-carousel-item v-for="img in skuImageList" :key="img.id">
                <img :src="img.imgUrl" />
              </el-carousel-item>
            </el-carousel>
          </div>
          <div class="mask"></div>
        </div>
        <div class="big">
          <img src="./image/商品介绍big1.jpg" alt="" />
        </div>
      </div>
      <!-- 产品介绍右侧 -->
      <div class="detail_ri">
        <!-- 产品参数及价格部分 -->
        <div class="parameter">
          <h2>{{ skuInfo.skuName }}</h2>
          <p class="orange">{{ skuInfo.skuDesc }}</p>
          <p class="gray">
            {{ skuInfo.skuGray }}
          </p>
          <p class="orange">小米自营</p>
          <span class="orange">{{ skuInfo.price }}元</span>
        </div>
        <!-- 地址部分制作 -->
        <div class="location">
          <em></em>
          <p>北京</p>
          <p>北京市</p>
          <p>海淀区</p>
          <p>滨水新区</p>
          <a href="" class="orange">修改</a>
          <i class="orange">有现货</i>
        </div>
        <!-- 选择版本部分制作 -->
        <dl class="version" v-for="attr in spuSaleAttrList" :key="attr.id">
          <dt>{{ attr.saleAttrName }}</dt>
          <dd
            @click="changeCheck(attrValue, attr.spuSaleAttrValueList)"
            v-for="attrValue in attr.spuSaleAttrValueList"
            :key="attrValue.id"
            :class="{ active: attrValue.isChecked === '1' }"
          >
            {{ attrValue.saleAttrValueName }}
          </dd>
        </dl>
        <!-- 总价部分 -->
        <div class="sum">
          <p class="sum1">Redmi Note 10 Pro 6GB+128GB 星纱</p>
          <p>1699元</p>
          <h2 class="orange">总计：1699元</h2>
        </div>
        <!-- 按钮部分 -->
        <div class="clickbutton">
          <!-- 加入购物车部分 -->
          <div class="join">
            <a class="join_car" @click="addShopCart">加入购物车</a>
          </div>
          <!-- 喜欢部分 -->
          <div class="like">
            <a href="" class="like_ai">喜欢</a>
          </div>
        </div>
        <!-- 备注部分 -->
        <div class="remarks">
          <li>
            <i></i>
            <em>小米自营</em>
          </li>
          <li>
            <i></i>
            <em>小米发货</em>
          </li>
          <li>
            <i></i>
            <em>7天无理由退货</em>
          </li>
          <li>
            <i></i>
            <em>运费说明</em>
          </li>
          <li>
            <i></i>
            <em>企业信息</em>
          </li>
          <li>
            <i></i>
            <em>7天价格保护</em>
          </li>
        </div>
      </div>
    </div>
    <!-- 价格说明部分制作 -->
    <div class="explain">
      <div class="w">
        <h2>价格说明</h2>
        <div class="explain_img">
          <img src="./image/价格说明.jpeg" alt="" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  name: "MiDetail",
  data() {
    return {
      skuId: this.$route.params.skuId, //商品id
      skuNum: 1, //商品数量
    };
  },
  computed: {
    ...mapGetters(["categoryView", "skuInfo", "spuSaleAttrList"]),
    skuImageList() {
      return this.skuInfo.skuImageList || [];
    },
  },
  methods: {
    getGoodsDetailInfo() {
      this.$store.dispatch("getGoodsDetailInfo");
    },
    //属性点击
    changeCheck(attrValue, spuSaleAttrValueList) {
      //属性值列表全部isChecked为0
      spuSaleAttrValueList.forEach((value) => {
        value.isChecked = "0";
      });
      //当前点击的这个属性值isChecked为1
      attrValue.isChecked = "1";
    },
    //点击添加购物车
    addShopCart() {
      this.$store.dispatch("getAddShopCart", {
        skuId: this.skuId,
        skuNum: this.skuNum,
      });

      let goodsInfo = {
        name: this.skuInfo.skuName,
        price: this.skuInfo.price,
        num: this.skuNum,
        imgUrl: this.skuInfo.skuDefaultImg,
        attrs: [],
        id: this.skuId,
      };
      this.spuSaleAttrList.forEach((attr) => {
        // 遍历取到每一个属性对象
        let checkedValue = attr.spuSaleAttrValueList.find((value) => {
          // 取到这个属性下面选中到的那个属性值的对象
          return value.isChecked === "1";
        });
        // 拼串  属性名:属性值
        let str = `${attr.saleAttrName}:${checkedValue.saleAttrValueName}`;
        goodsInfo.attrs.push(str);
      });

      // 数据存储在sessionStorage
      sessionStorage.setItem("goodsInfo", JSON.stringify(goodsInfo));

      this.$router.push({
        path: "/addcartsuccess",
      });
    },
  },
  mounted() {
    this.getGoodsDetailInfo();
    //   var box = document.getElementsByClassName("detail_le")[0];
    //   var small = box.children[0];
    //   var big = box.children[1];
    //   var bigImg = big.children[0];
    //   var mask = small.children[1];

    //   //big和mask在鼠标移入small时显示，移出时隐藏
    //   small.onmouseenter = function () {
    //     big.style.display = "block";
    //     mask.style.display = "block";
    //   };
    //   small.onmouseleave = function () {
    //     big.style.display = "none";
    //     mask.style.display = "none";
    //   };

    //   small.onmousemove = function (event) {
    //     event = event || window.event;
    //     //mask跟随鼠标移动，且不会超出small范围
    //     //x作为mask的left值，y作mask的top值。
    //     var pagex = event.pageX || scroll().left + event.clientX;
    //     var pagey = event.pageY || scroll().top + event.clientY;

    //     //减去mask宽高的一半，让鼠标在mask的中间
    //     var x = pagex - box.offsetLeft - mask.offsetWidth / 2;
    //     var y = pagey - box.offsetTop - mask.offsetHeight / 2;

    //     //不让mask超出small
    //     if (x < 0) {
    //       x = 0;
    //     }
    //     if (x > small.offsetWidth - mask.offsetWidth) {
    //       x = small.offsetWidth - mask.offsetWidth;
    //     }
    //     if (y < 0) {
    //       y = 0;
    //     }
    //     if (y > small.offsetHeight - mask.offsetHeight) {
    //       y = small.offsetHeight - mask.offsetHeight;
    //     }

    //     mask.style.left = x + "px";
    //     mask.style.top = y + "px";

    //     //bigImg随着mask的移动移动
    //     //比例 = 大图移动的距离/mask移动的距离 = 大图/小图
    //     var scale = bigImg.offsetWidth / small.offsetWidth;

    //     bigImg.style.marginLeft = -scale * x + "px";
    //     bigImg.style.marginTop = -scale * y + "px";
    //   };
  },
};
</script>

<style lang="less" scoped>
/* 产品导航栏部分 */

.brief {
  position: sticky;
  top: 0px;
  height: 60px;
  line-height: 60px;
  background-color: #fff;
  overflow: hidden;
  z-index: 1;
  box-shadow: 0px 4px 15px rgba(0, 0, 0, 0.2);
}

/* 产品导航栏左侧 */

.brief_le {
  float: left;
}

.brief_le h3 {
  display: inline-block;
  font-weight: 400;
}

.brief_le a {
  display: inline-block;
  color: #616161;
  font-size: 12px;
}

.brief_le a:hover {
  color: orange;
}

/* 产品导航栏右侧 */

.brief_ri {
  float: right;
}

.brief_ri a {
  color: #616161;
}

.brief_ri a:hover {
  color: orange;
}

.brief_ri span {
  color: #e0e0e0;
  margin: 0 5px;
}

/* 产品介绍部分 */
.version .active {
  color: #ff6700;
  border: 1px solid #ff6700;
}

:deep(.el-carousel__container) {
  z-index: 0;
  height: 500px;
  margin-top: 30px;
}

:deep(.el-carousel__indicators) {
  margin-top: -10px;
}

:deep(.el-carousel__indicator--horizontal) {
  display: inline-block;
  padding: 0 4px;
}

:deep(.el-carousel__arrow) {
  border-radius: 0%;
  height: 67px;
  font-size: 30px;
}
:deep(.el-carousel__arrow--left) {
  left: 0px;
}
:deep(.el-carousel__arrow--right) {
  right: 0px;
}

.detail {
  margin-top: 30px;
}

.detail_le {
  position: relative;
  float: left;
  width: 560px;
  height: 560px;
}

.detail_le .small {
  position: relative;
  width: 560px;
  height: 560px;
}

.detail_le .small img {
  width: 560px;
  height: 560px;
}

.detail_le .big {
  width: 270px;
  height: 270px;
  border: 1px solid #fff;
  position: absolute;
  top: 60px;
  left: 580px;
  overflow: hidden;
  display: none;
}

.small .mask {
  z-index: 5;
  width: 175px;
  height: 175px;
  background: rgba(255, 255, 0, 0.4);
  position: absolute;
  left: 0;
  top: 0;
  display: none;
  cursor: move;
}

.detail_ri {
  float: right;
  width: 600px;
}
.parameter {
  margin-top: 50px;
}
.parameter h2 {
  text-align: left;
  margin-bottom: 10px;
}

.parameter p {
  margin-bottom: 10px;
}

.parameter span {
  display: block;
  font-size: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid #ddd;
}

.orange {
  color: #ff4a00;
}

.gray {
  color: #b0b0b0;
  margin-bottom: 10px;
}

/* 地址部分制作 */

.location {
  height: 104px;
  margin-top: 20px;
  margin-bottom: 20px;
  padding: 20px 10px;
  border: 1px solid #ddd;
  background-color: #fafafa;
}

.location em::before {
  font-family: "icomoon";
  content: "\ea0e";
  color: #b0b0b0;
  vertical-align: center;
}

.location p {
  display: inline;
  margin-right: 15px;
}

.location i {
  display: block;
  margin-top: 10px;
  margin-left: 20px;
}

/* 选择版本部分 */

.version dt {
  font-size: 14px;
  font-weight: 400;
  margin-bottom: 10px;
}

.version dd {
  display: inline-block;
  margin-right: 5px;
  margin-bottom: 10px;
  width: 292px;
  height: 44px;
  color: #757575;
  font-size: 18px;
  line-height: 44px;
  border: 1px solid #ddd;
  text-align: center;
}

.version dd:hover {
  border: 1px solid #ff6700;
  color: #ff6700;
}

.version dd:active {
  border: 1px solid #ff6700;
  color: #ff6700;
}

/* 选择版本部分 */

.select_color dt {
  font-size: 14px;
  font-weight: 400;
  margin-bottom: 10px;
}

.select_color dd {
  display: inline-block;
  margin-right: 5px;
  margin-bottom: 10px;
  width: 292px;
  height: 44px;
  color: #757575;
  font-size: 18px;
  line-height: 44px;
  border: 1px solid #ddd;
  text-align: center;
}

.select_color dd:hover {
  border: 1px solid #ff6700;
  color: #ff6700;
}

.select_color dd:active {
  border: 1px solid #ff6700;
  color: #ff6700;
}

.sum {
  height: 100px;
  padding: 30px 20px 20px 30px;
  border: 1px solid #ddd;
  background-color: #f5f5f5;
  margin-bottom: 20px;
}

.sum p {
  display: inline;
  color: #616161;
  font-size: 14px;
}

.sum .sum1 {
  margin-right: 200px;
}

.sum h2 {
  margin-top: 28px;
  font-weight: 400;
}

/* 加入购物车部分*/

.clickbutton {
  height: 54px;
  margin-bottom: 30px;
}

.join {
  float: left;
  width: 300px;
  height: 54px;
  line-height: 54px;
  text-align: center;
  background-color: #ff6700;
}

.join .join_car {
  display: block;
  color: #fff;
  font-size: 16px;
  transition: background-color 0.5s;
}

.join .join_car:hover {
  background-color: rgb(252, 162, 29);
}

/* 喜欢部分 */

.like {
  float: left;
  width: 142px;
  height: 54px;
  margin-left: 20px;
  line-height: 54px;
  text-align: center;
  background-color: rgb(177, 175, 175);
}

.like .like_ai {
  display: block;
  color: #fff;
  font-size: 16px;
  transition: background-color 0.5s;
}

.like .like_ai::before {
  font-family: "icomoon";
  content: "\e909";
  vertical-align: middle;
  font-size: 20px;
}

.like .like_ai:hover {
  background-color: gray;
}

/* 备注部分 */

@font-face {
  font-family: "icomoon";
  src: url("./fonts/icomoon.eot?c0p1ov");
  src: url("./fonts/icomoon.eot?c0p1ov#iefix") format("embedded-opentype"),
    url("./fonts/icomoon.ttf?c0p1ov") format("truetype"),
    url("fonts/icomoon.woff?c0p1ov") format("woff"),
    url("fonts/icomoon.svg?c0p1ov#icomoon") format("svg");
  font-weight: normal;
  font-style: normal;
  font-display: block;
}
.remarks li {
  display: block;
  float: left;
  color: #b0b0b0;
  margin-right: 20px;
  margin-bottom: 20px;
}

.remarks li i::before {
  padding-right: 3px;
  font-family: "icomoon";
  content: "\e9c0";
  font-size: 20px;
  vertical-align: middle;
}

/* 价格说明部分 */

.explain {
  background-color: #f5f5f5;
  height: 325px;
  clear: both;
}

.explain h2 {
  display: inline-block;
  height: 76px;
  line-height: 76px;
  font-weight: 400;
  margin-bottom: 10px;
}

.explain .explain_img {
  width: 1226px;
  height: 189px;
}

/* 清除浮动 */

.footer {
  clear: both;
}

.w {
  width: 1226px;
  margin: 0 auto;
}

@keyframes move {
  0% {
    height: 0px;
  }
  100% {
    height: 97px;
  }
}

/* 头部样式 */

.header {
  /* position: sticky; */
  top: 0;
  height: 40px;
  line-height: 40px;
  text-align: center;
  font-size: 12px;
  background-color: #333333;
  z-index: 6;
}

.header_le {
  float: left;
}

.header_le ul li {
  float: left;
}

.header_le ul li a {
  display: inline-block;
  color: #b0b0b0;
  height: 40px;
}

.header_le ul li span {
  margin: 0 4.5px;
  color: #424242;
}

.header_le a:hover {
  color: #fff;
}

.header_ri {
  float: right;
}

.header_ri .enter {
  float: left;
  margin-right: 20px;
}

.header_ri .enter ul li {
  float: left;
}

.header_ri .enter ul li a {
  display: inline-block;
  color: #b0b0b0;
}

.header_ri .enter a:hover {
  color: #fff;
}

/* 购物车模块样式 */

.header_ri .shopcar {
  position: relative;
  float: right;
  width: 120px;
  height: 40px;
  font-size: 12px;
  color: #b0b0b0;
  background-color: #424242;
}

.shopcar:hover {
  cursor: pointer;
  color: orange;
  background-color: #fff;
}

.shopcar span::before {
  font-family: "icomoon";
  content: "\e979";
  font-size: 14px;
  vertical-align: middle;
}

.shopcar_detail {
  display: none;
  position: absolute;
  top: 40px;
  right: 0px;
  width: 316px;
  height: 95px;
  background-color: #fff;
  z-index: 1;
  padding-top: 20px;
  box-shadow: 2px 6px 8px #b0b0b0;
  /* animation: move .5s ease 1; */
  animation: move 0.5s cubic-bezier(0.18, 0.89, 0.32, 1.28) 1;
}

.shopcar:hover .shopcar_detail {
  display: block;
}

.nav {
  position: relative;
  margin-top: 10px;
  height: 88px;
  line-height: 88px;
  vertical-align: middle;
}

.logo {
  position: absolute;
  left: 0;
  top: 13px;
  width: 56px;
  height: 56px;
}

.nav .logo h1 {
  display: block;
  width: 56px;
  height: 56px;
}

.nav .logo h1 a {
  display: block;
  width: 56px;
  height: 56px;
  font-size: 0;
  background: url(./image/logo-mi2.png) no-repeat;
  background-size: cover;
}

.nav .nav_mi {
  float: left;
  margin-left: 240px;
}

.nav .nav_mi ul li {
  float: left;
  height: 88px;
  line-height: 88px;
  margin: 0 10px;
  cursor: pointer;
}

.nav .nav_mi ul li a {
  color: #000;
}

.nav_mi ul li:hover a {
  color: orange;
}

.nav_mi ul li:hover {
  border-bottom: 2px solid orange;
}

.search {
  float: right;
}

.search .search_1 {
  width: 200px;
  height: 50px;
  border: 1px solid #e0e0e0;
}

.search .search_2 {
  float: right;
  margin-top: 19px;
  width: 50px;
  height: 51px;
  border: 1px solid #e0e0e0;
  border-left: 0px;
  background: #fff;
}

.search_2::after {
  font-family: "icomoon";
  content: "\e986";
  font-size: 18px;
  vertical-align: middle;
}

.search_1:hover {
  border: 1px solid #424242;
}

.search_2:hover {
  background-color: #ff6700;
  color: #fff;
}

/* 尾部区域 */

.footer {
  background-color: #fff;
}

/* 尾部区域服务模块 */

.footer .serve {
  height: 80px;
  line-height: 80px;
  border-bottom: 1px solid #ddd;
}

.footer .serve ul li {
  float: left;
  text-align: center;
  width: 245px;
}

.footer .serve ul li a {
  color: #616161;
}

/* 这里为每个服务添加图标 */

.footer .serve ul li .serve_1::before {
  font-family: "icomoon";
  content: "\ea90";
  font-size: 24px;
  vertical-align: bottom;
  margin-right: 5px;
}

.footer .serve ul li .serve_2::before {
  font-family: "icomoon";
  content: "\e94e";
  font-size: 24px;
  vertical-align: bottom;
  margin-right: 5px;
}

.footer .serve ul li .serve_3::before {
  font-family: "icomoon";
  content: "\e9eb";
  font-size: 24px;
  vertical-align: bottom;
  margin-right: 5px;
}

.footer .serve ul li .serve_4::before {
  font-family: "icomoon";
  content: "\e9f4";
  font-size: 24px;
  vertical-align: bottom;
  margin-right: 5px;
}

.footer .serve ul li .serve_5::before {
  font-family: "icomoon";
  content: "\ea0e";
  font-size: 24px;
  vertical-align: bottom;
  margin-right: 5px;
}

.footer .serve ul li a:hover {
  color: #ff6709;
}

/* 尾部区域指南模块 */

.guild {
  margin-top: 30px;
  height: 250px;
}

/* 尾部区域指南左侧模块 */

.guild_le {
  float: left;
}

.guild_le dl {
  float: left;
  width: 160px;
}

.guild_le dl dt {
  margin-bottom: 10px;
  font-size: 14px;
}

.guild_le dl dd {
  margin: 5px 0;
}

.guild_le dl dd a {
  font-size: 12px;
  color: #757575;
}

.guild_le dl dd a:hover {
  color: #ff6709;
}

/* 尾部区域指南右侧模块 */

.guild_ri {
  float: left;
  width: 266px;
  text-align: center;
  border-left: 1px solid #ddd;
}

.guild_ri h2 {
  color: #ff6709;
}

.guild_ri .time {
  font-size: 12px;
  color: #757575;
}

.guild_ri .customer {
  display: inline-block;
  width: 120px;
  height: 30px;
  line-height: 30px;
  text-align: center;
  font-size: 12px;
  color: #ff6709;
  border: 1px solid #ff6709;
  transition: background-color 0.6s;
}

.guild_ri .customer::before {
  font-family: "icomoon";
  content: "\e9bf";
  vertical-align: bottom;
  margin-right: 5px;
}

.guild_ri .customer:hover {
  background-color: #ff6709;
  color: #fff;
}

.guild_ri .view {
  margin-top: 10px;
  font-size: 14px;
  color: #757575;
}

.guild_ri .view a {
  color: #5f5750;
}

.guild_ri .view .qq::before {
  font-family: "icomoon";
  content: "\e908";
}

.guild_ri .view .fire::before {
  font-family: "icomoon";
  content: "\e911";
}

.guild_ri .view a:hover {
  color: #ff6709;
}
</style>
